class Root:
    def draw(self):
        # the delegation chain stops here
        assert not hasattr(super(), 'draw')


class Shape(Root):
    def __init__(self, shapename, **kwds):  # 3同上，迭代地捕获所需参数shapename，并将之后的一切参数使用字典捕获
        self.shapename = shapename
        super().__init__(**kwds)  # 4
    def draw(self):
        print('Drawing.  Setting shape to:', self.shapename)
        super().draw()


class ColoredShape(Shape):
    def __init__(self, color, **kwds):  # 1迭代地捕获所需参数color，之后的一切参数使用字典捕获
        self.color = color
        super().__init__(**kwds)  # 2除第一个参数外，其余参数传给父类
    def draw(self):
        print('Drawing.  Setting color to:', self.color)
        super().draw()


if __name__ == '__main__':
    cs = ColoredShape(color='blue', shapename='square')
    cs.draw()
# cooperative的含义：整个继承链条完全由自己设计，所以可以用如上的迭代**kwds捕获法！
